package com.lamda.zhekou.master.event;


import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.lamda.zhekou.master.session.WorkerSessionScheduler;

/**
 * Created by Administrator on 2015/1/20 0020.
 */
public class Protocol {

    public static String encode(int reqId, String route, JSONObject msg) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put(WorkerSessionScheduler.SERVER_TO_CLIENT_REQ_ID_FLAG, reqId); //服务器端的请求ID
            jsonObject.put("route", route);
            jsonObject.put("msg", msg);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return new StringBuilder(jsonObject.toString()).append("\r\n").toString();
    }
    public static String encode(String route, JSONObject msg) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("route", route);
            jsonObject.put("msg", msg);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return new StringBuilder(jsonObject.toString()).append("\r\n").toString();
    }
}
